/*
 * File Name:               XCacheData.cs
 * 
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2017/01/18
 */

using System;

public class XCacheData<T> : ICacheData
{
    private T mData;
    private bool hasValue = false;
    private Func<T> mCallback;

    public XCacheData(Func<T> callback)
    {
        mCallback = callback;
    }

    public void reset()
    {
        hasValue = false;
    }

    public T getValue()
    {
        if (hasValue)
            return mData;

        hasValue = true;
        mData = mCallback();
        return mData;
    }
}
